package com.duolaibei.pay.base;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;

import com.duolaibei.pay.smprint.AidlUtil;
import com.duolaibei.pay.utils.GreenDaoManager;
import com.iflytek.cloud.SpeechUtility;

/**
 * Created by xlm on 2017/8/17 0017
 */

public class AppIntentService extends IntentService {
    private static final String TAG = "AppIntentService";
    private static final String ACTION_INIT_WHEN_APP_CREATE = "com.mobilepay.pay.service.action.INIT";

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     */
    public AppIntentService() {
        super("AppIntentService");
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, AppIntentService.class);
        intent.setAction(ACTION_INIT_WHEN_APP_CREATE);
        context.startService(intent);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        if (intent != null) {
            final String action = intent.getAction();
            if (ACTION_INIT_WHEN_APP_CREATE.equals(action)) {
                performInit();
            }
        }
    }

    private void performInit() {
        GreenDaoManager.getInstance();
        // Setting.setShowLog(false);
        SpeechUtility.createUtility(this.getApplicationContext(), "appid=592fc99f");
        AidlUtil.getInstance().connectPrinterService(this.getApplicationContext());//初始化商米打印机
    }

}
